package sis.ra.pattern.pmi;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import sis.ra.partofspeech.wordindex;
import sis.ra.utility.Utils;
import sis.ra.yahoor.result.extractPattern;
import sis.ra.yahoor.result.parseYahooResults;


public class verbfreq {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String file="C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.snippetCP";
		String content=Utils.readFile(file);
		
		String [] lines=content.split("\n");
		int compprodpair=0;
		HashMap<String, Integer> verbs=new HashMap<String, Integer> ();
		String filename="";
		for (int i=0;i<lines.length;i++)
		{
			String line=lines[i];
			if (line.length()<2) continue;
			if (lines[i].startsWith("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\yahoo result_1006\\"))
			{
		//		System.out.println(lines[i]);
				filename=line;
				
			} else
			if (lines[i].startsWith("COMPANYPRODUCT: "))
			{
				System.out.println("Company Product Pair: "+ compprodpair);
				Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.verbstat", "Company Product Pair: "+ compprodpair,true,true);
				compprodpair=0;
				
				Iterator<String> it=verbs.keySet().iterator();
				while (it.hasNext())
				{
					String v=it.next();
					System.out.println("verb "+v+"\t"+verbs.get(v));
					Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.verbstat", "verb "+v+"\t"+verbs.get(v),true,true);
				}
				verbs=new HashMap<String, Integer> ();
				System.out.println(lines[i]);	
				System.out.println(filename);	
				
				Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.verbstat", filename,true,true);
				Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.verbstat", lines[i],true,true);
			}else
			{
				if (line.startsWith("==>")) compprodpair=compprodpair+1;
				line=line.substring(3);
				
				HashMap<Integer,wordindex> posresult=parseYahooResults.pos(line, "text");
				ArrayList<String> resultlist=parseYahooResults.getResultList (posresult);
				String result="";
				String analysis="";
				boolean containVerb=false;
				String verb="";
				int verbpos=0;
				
				//verb
				for (int n=0;n<resultlist.size();n++)
				{
					if (resultlist.get(n).contains("V-"))
					{
						verb=resultlist.get(n).split("\t")[1];
						String stemed=extractPattern.stem(verb);
						if (verbs.keySet().contains(stemed))
						{
							Integer newcount=verbs.get(stemed)+1;
							verbs.remove(stemed);
							verbs.put(stemed, newcount);
						}else
						{
							verbs.put(stemed, 1);
						}
					}
							
				}
			}
		}
		System.out.println("Company Product Pair: "+ compprodpair);
		Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.verbstat", "Company Product Pair: "+ compprodpair,true,true);
		compprodpair=0;
		
		Iterator<String> it=verbs.keySet().iterator();
		while (it.hasNext())
		{
			String v=it.next();
			System.out.println("verb "+v+"\t"+verbs.get(v));
			Utils.writeToFile("C:\\Documents and Settings\\I820753\\Desktop\\dataset\\result1006.verbstat", "verb "+v+"\t"+verbs.get(v),true,true);
		}
	}

}
